local tuqian = fk.CreateSkill{
  name = "hanqing__tuqian",
}

Fk:loadTranslationTable{
  ["hanqing__tuqian"] = "屠愆",
  [":hanqing__tuqian"] = "出牌阶段限一次，你可以声明将视为使用一张火【杀】或【火攻】，令所有角色明置两张手牌，对任意名未明置红色牌的角色"..
  "使用之。若目标唯一，此牌伤害+1；若没有目标，则皆成为目标（无视合法性）。",

  ["#hanqing__tuqian"] = "屠愆：声明火【杀】或【火攻】，令所有角色明置两张手牌，你对不展示红色牌的角色使用之",
  ["#hanqing__tuqian-ask"] = "屠愆：%src 声明【%arg】，请明置两张手牌，若不展示红色牌则对你使用！",
}

local DIY = require "packages/diy_utility/diy_utility"

tuqian:addEffect("active", {
  anim_type = "offensive",
  prompt = "#hanqing__tuqian",
  card_num = 0,
  target_num = 0,
  interaction = UI.CardNameBox {choices = {"fire__slash", "fire_attack"}},
  can_use = function(self, player)
    return player:usedSkillTimes(tuqian.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    room:doIndicate(player, room.alive_players)
    room:playCardEmotionAndSound(player, Fk:cloneCard(self.interaction.data))

    local req = Request:new(room.alive_players, "AskForUseActiveSkill")
    req.focus_text = tuqian.name
    for _, p in ipairs(room.alive_players) do
      local cards = table.filter(p:getCardIds("h"), function (id)
        return not table.contains(DIY.getShownCards(p), id)
      end)
      local extraData = {
        num = 2,
        min_num = math.min(#cards, 2),
        include_equip = false,
        pattern = tostring(Exppattern{ id = cards }),
        reason = tuqian.name,
      }
      local data = {
        "choose_cards_skill",
        "#hanqing__tuqian-ask:"..player.id.."::"..self.interaction.data,
        false,
        extraData,
      }
      req:setData(p, data)
      req:setDefaultReply(p, table.random(cards, 2))
    end
    req:ask()

    local targets = {}
    for _, p in ipairs(room:getAlivePlayers()) do
      local ids = {}
      local result = req:getResult(p)
      if result ~= "" then
        if result.card then
          ids = result.card.subcards
        else
          ids = result
        end
      end
      if #ids > 0 then
        DIY.showCards(p, ids)
      end
      if not table.find(ids, function (id)
        return Fk:getCardById(id).color == Card.Red
      end) then
        table.insert(targets, p)
      end
    end

    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = tuqian.name
    local use = {
      from = player,
      tos = {},
      card = card,
      extraUse = true,
    }
    if #targets == 0 or (#targets == 1 and self.interaction.data == "fire__slash" and targets[1] == player) then
      targets = room:getAlivePlayers()
    else
      if #targets == 1 then
        use.additionalDamage = (use.additionalDamage or 0) + 1
      end
      targets = table.filter(targets, function (p)
        return not p.dead and not (self.interaction.data == "fire__slash" and p == player)
      end)
    end
    if #targets > 0 then
      use.tos = targets
      room:useCard(use)
    end
  end,
})

return tuqian
